package com.zzxx.wechat.service.impl;

import com.zzxx.wechat.adpater.ArcteryxAdapter;
import com.zzxx.wechat.common.enums.ArcteryxSpuStatusEnum;
import com.zzxx.wechat.common.vo.ArcteryxProductReq;
import com.zzxx.wechat.common.vo.ArcteryxProductVo;
import com.zzxx.wechat.dao.ArcteryxProductDao;
import com.zzxx.wechat.entity.ArcteryxProduct;
import com.zzxx.wechat.service.ArcteryxProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class ArcteryxProductServiceImpl implements ArcteryxProductService {

    @Resource
    private ArcteryxProductDao arcteryxProductDao;


    public List<ArcteryxProductVo> list() {

        List<ArcteryxProduct> arcteryxProducts = arcteryxProductDao.list();

        return ArcteryxAdapter.arcteryxProduct2Vos(arcteryxProducts);

    }

    public void add(ArcteryxProductReq req) {

        ArcteryxProduct arcteryxProduct = arcteryxProductDao.queryByNo(req.getProductNo());
        if (arcteryxProduct == null) {
            arcteryxProductDao.saveByNoColor(req.getProductNo(), req.getColor());
        }

    }


    public void delete(ArcteryxProductReq req) {

        ArcteryxProduct arcteryxProduct = arcteryxProductDao.queryByNo(req.getProductNo());
        if (arcteryxProduct != null) {
            arcteryxProductDao.removeById(arcteryxProduct.getId());
        }

    }

    public void updateStatus(String productNo, ArcteryxSpuStatusEnum arcteryxSpuStatusEnum) {

        ArcteryxProduct arcteryxProduct = arcteryxProductDao.queryByNo(productNo);
        if (arcteryxProduct != null) {
            arcteryxProduct.setStatusCode(arcteryxSpuStatusEnum.getCode());
            arcteryxProductDao.updateById(arcteryxProduct);
        }
    }

}
